//
//  NewFeatureCell.m
//  weibo
//
//  Created by qiuming on 15/12/25.
//  Copyright © 2015年 qiuming. All rights reserved.
//

#import "NewFeatureCell.h"
#import "AppDelegate.h"

@interface NewFeatureCell()
@property (strong, nonatomic) UIImageView *guideView;
@property (strong, nonatomic) UIButton *startBtn;
@property (strong, nonatomic) UIButton *sharedBtn;



@end
@implementation NewFeatureCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}



- (void)setupUI {
    // 添加控件
    [self addSubview:self.guideView];
    [self addSubview:self.sharedBtn];
    [self addSubview:self.startBtn];
    
    // 自动布局
    [self.guideView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.bottom.equalTo(self.mas_bottom);
        make.right.equalTo(self.mas_right);
    }];
    
    [self.sharedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.mas_centerX);
        make.bottom.equalTo(self.startBtn.mas_top).offset(-20);
    }];
    
    [self.startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.sharedBtn.mas_centerX);
        make.bottom.mas_equalTo(-140);
    }];
}


/// 隐藏分享和开始按钮
- (void)setSharedBtnAndStartBtnHidden:(BOOL)hidden {
    self.sharedBtn.hidden = hidden;
    self.startBtn.hidden = hidden;
}

- (void)setImageName:(NSString *)imageName {
    _imageName = imageName;
    self.guideView.image = [UIImage imageNamed:imageName];
}

/// 分享按钮
- (void)sharedBtnClick {
    self.sharedBtn.selected = !self.sharedBtn.selected;
    DDLogError(@"分享按钮");
}

/// 进入主页
- (void)startBtnClick {
    
    [[NSNotificationCenter defaultCenter] postNotificationName:SwitchRootViewControllerNotification object:nil];
}


// MARK: - 懒加载
- (UIImageView *)guideView {
    if (_guideView == nil) {
        _guideView = [[UIImageView alloc]init];
    }
    return _guideView;
}

- (UIButton *)startBtn {
    if (_startBtn == nil) {
        
        _startBtn = [UIButton btnWithTitle:@"进入主页" titleColor:[UIColor whiteColor] backgroundImage:@"new_feature_finish_button"];
        
        [_startBtn addTarget:self action:@selector(startBtnClick)];
        }
    return _startBtn;
}

- (UIButton *)sharedBtn {
    if (_sharedBtn == nil) {
        _sharedBtn = [[UIButton alloc]init];
        [_sharedBtn setTitle:@"分享到微博" forState:UIControlStateNormal];
        [_sharedBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [_sharedBtn setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
        [_sharedBtn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
        [_sharedBtn sizeToFit];
        [_sharedBtn addTarget:self action:@selector(sharedBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sharedBtn;
}
@end
